const getLoginURL = (backurl?: string) => {
  const url =
    process.env.NEXT_PUBLIC_LOGIN_URL +
    '?return_url=' +
    encodeURIComponent(
      location.origin +
        '/api/login?backurl=' +
        (backurl || window.location.href)
    );

  return url;
};

const goLogin = (backurl?: string) => {
  window.location.href = getLoginURL(backurl);
};

const getLogoutURL = (backurl?: string) => {
  const url =
    location.origin +
    '/api/logout?backurl=' +
    encodeURIComponent(
      process.env.NEXT_PUBLIC_LOGOUT_URL +
        '?return_url=' +
        (backurl || window.location.href)
    );
  return url;
};

const goLogout = (backurl?: string) => {
  window.location.href = getLogoutURL(backurl);
};
export { getLoginURL, goLogin, getLogoutURL, goLogout };
